#!/usr/bin/env python
#coding=utf-8

from sqlalchemy import func

from aladin.database import db

class User(db.Model):
    __tablename__ = 'user'

    uid            = db.Column(db.Integer, primary_key=True)
    gid            = db.Column(db.Integer, default=0)
    password       = db.Column(db.String(32), default='')
    salt           = db.Column(db.String(6), default='')
    username       = db.Column(db.String(32), default='')
    nickname       = db.Column(db.String(32), default='')
    realname       = db.Column(db.String(32), default='')
    gender         = db.Column(db.Integer, default=0)
    birth_year     = db.Column(db.Integer, default=0)
    mobile         = db.Column(db.String(16), default='')
    mobile_status  = db.Column(db.Integer, default=0)
    email          = db.Column(db.String(128), default='')
    email_status   = db.Column(db.Integer, default=0)
    avatar         = db.Column(db.String(255), default='')
    avatar_small   = db.Column(db.String(255), default='')
    avatar_big     = db.Column(db.String(255), default='')
    signature      = db.Column(db.String(255), default='')
    regtime        = db.Column(db.Integer, default=0)
    regip          = db.Column(db.String(15), default='')
    lastvisit      = db.Column(db.Integer, default=0)
    lastip         = db.Column(db.String(15), default='')
    jingdu         = db.Column(db.Float, default=None)
    weidu          = db.Column(db.Float, default=None)
    auto_nation    = db.Column(db.String(32), default='')
    auto_province  = db.Column(db.String(32), default='')
    auto_city      = db.Column(db.String(32), default='')
    auto_district  = db.Column(db.String(32), default='')
    nation         = db.Column(db.String(32), default='')
    province       = db.Column(db.String(32), default='')
    city           = db.Column(db.String(32), default='')
    district       = db.Column(db.String(32), default='')
    version        = db.Column(db.String(255), default='')
    vendor         = db.Column(db.String(64), default='')
    os             = db.Column(db.String(16), default='')
    osver          = db.Column(db.String(16), default='')
    device         = db.Column(db.String(32), default='')
    pushtoken      = db.Column(db.String(255), default='')
    id_no          = db.Column(db.String(32), default='')
    hx_name        = db.Column(db.String(32), default='')
    hx_pwd         = db.Column(db.String(32), default='')
    is_real        = db.Column(db.Integer, default=0)
    is_cert        = db.Column(db.Integer, default=0)
    teacher_status = db.Column(db.Integer, default=0)

    def __str__(self):
        return "User => { \
uid:%d, gid:%d, password:'%s', salt:'%s', username:'%s',  \
nickname:'%s', realname:'%s', gender:%d, birth_year:%d, mobile:'%s',  \
mobile_status:%d, email:'%s', email_status:%d, avatar:'%s', avatar_small:'%s',  \
avatar_big:'%s', signature:'%s', regtime:%d, regip:'%s', lastvisit:%d,  \
lastip:'%s', jingdu:%0.2f, weidu:%0.2f, auto_nation:'%s', auto_province:'%s',  \
auto_city:'%s', auto_district:'%s', nation:'%s', province:'%s', city:'%s',  \
district:'%s', version:'%s', vendor:'%s', os:'%s', osver:'%s',  \
device:'%s', pushtoken:'%s', id_no:'%s', hx_name:'%s', hx_pwd:'%s',  \
is_real:%d, is_cert:%d, teacher_status:%d}" % (
self.uid, self.gid, self.password, self.salt, self.username, 
self.nickname, self.realname, self.gender, self.birth_year, self.mobile, 
self.mobile_status, self.email, self.email_status, self.avatar, self.avatar_small, 
self.avatar_big, self.signature, self.regtime, self.regip, self.lastvisit, 
self.lastip, self.jingdu, self.weidu, self.auto_nation, self.auto_province, 
self.auto_city, self.auto_district, self.nation, self.province, self.city, 
self.district, self.version, self.vendor, self.os, self.osver, 
self.device, self.pushtoken, self.id_no, self.hx_name, self.hx_pwd, 
self.is_real, self.is_cert, self.teacher_status)

    __repr__ = __str__


class UserGroup(db.Model):
    __tablename__ = 'user_group'

    gid        = db.Column(db.Integer, primary_key=True)
    group_name = db.Column(db.String(255), default='')
    add_time   = db.Column(db.Integer, default=0)

    def __str__(self):
        return "UserGroup => { \
gid:%d, group_name:'%s', add_time:%d}" % (
self.gid, self.group_name, self.add_time)

    __repr__ = __str__


class UserCheckCode(db.Model):
    __tablename__ = 'user_check_code'

    id = db.Column(db.Integer, primary_key=True)
    mobile = db.Column(db.String(11), default=None)
    check_code = db.Column(db.String(16), default='')
    expire_time = db.Column(db.Integer, default=0)
    check_type = db.Column(db.Integer, default=0)

    def __str__(self):
        return "UserCheckCode => { \
id:%d, mobile:'%s', check_code:'%s', expire_time:%d, check_type:%d}" % (
self.id, self.mobile, self.check_code, self.expire_time, self.check_type)

    __repr__ = __str__


class UserCheckHistory(db.Model):
    __tablename__ = 'user_check_history'

    id         = db.Column(db.Integer, primary_key=True)
    mobile     = db.Column(db.String(16), default=None)
    code       = db.Column(db.String(6), default=None)
    check_time = db.Column(db.Integer, default=0)

    def __str__(self):
        return "UserCheckHistory => { \
id:%d, mobile:'%s', code:'%s', check_time:%d}" % (
self.id, self.mobile, self.code, self.check_time)

    __repr__ = __str__


class UserScore(db.Model):
    __tablename__ = 'user_score'

    id         = db.Column(db.Integer, primary_key=True)
    uid        = db.Column(db.Integer, default=0)
    score      = db.Column(db.Integer, default=0)
    score_desc = db.Column(db.String(255), default='')
    score_type = db.Column(db.Integer, default=0)
    add_time   = db.Column(db.Integer, default=0)

    def __str__(self):
        return "UserScore => { \
id:%d, uid:%d, score:%d, score_desc:'%s', score_type:%d,  \
add_time:%d}" % (
self.id, self.uid, self.score, self.score_desc, self.score_type, 
self.add_time)

    __repr__ = __str__


class UserImage(db.Model):
    __tablename__ = 'user_image'

    id           = db.Column(db.Integer, primary_key=True)
    uid          = db.Column(db.Integer, default=0)
    tid          = db.Column(db.Integer, default=0)
    type         = db.Column(db.Integer, default=0)
    img_url      = db.Column(db.String(255), default='')
    img_thumb    = db.Column(db.String(255), default='')
    img_original = db.Column(db.String(255), default='')
    add_time     = db.Column(db.Integer, default=0)
    cherker      = db.Column(db.String(32), default='')
    status       = db.Column(db.Integer, default=0)
    check_time   = db.Column(db.Integer, default=0)
    is_delete    = db.Column(db.Integer, default=0)

    def __str__(self):
        return "UserImage => { \
id:%d, uid:%d, tid:%d, type:%d, img_url:'%s',  \
img_thumb:'%s', img_original:'%s', add_time:%d, cherker:'%s', status:%d,  \
check_time:%d}" % (
self.id, self.uid, self.tid, self.type, self.img_url, 
self.img_thumb, self.img_original, self.add_time, self.cherker, self.status, 
self.check_time)

    __repr__ = __str__


class UserAdmin(db.Model):
    __tablename__ = 'user_admin'

    id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.Integer, default=0)
    add_time = db.Column(db.Integer, default=0)

    def __str__(self):
        return "UserAdmin => { \
id:%d, uid:%d, add_time:%d}" % (
self.id, self.uid, self.add_time)

    __repr__ = __str__


class UserRealnameApply(db.Model):
    __tablename__ = 'user_realname_apply'

    id           = db.Column(db.Integer, primary_key=True)
    uid          = db.Column(db.Integer, default=0)
    apply_time   = db.Column(db.Integer, default=0)
    status       = db.Column(db.Integer, default=0)
    check_time   = db.Column(db.Integer, default=0)
    checker      = db.Column(db.String(32), default='')
    realname     = db.Column(db.String(32), default='')
    id_no        = db.Column(db.String(32), default='')
    id_pic_front = db.Column(db.String(255), default='')
    id_pic_back  = db.Column(db.String(255), default='')

    def __str__(self):
        return "UserRealnameApply => { \
id:%d, uid:%d, apply_time:%d, status:%d, check_time:%d,  \
checker:'%s', realname:'%s', id_no:'%s', id_pic_front:'%s', id_pic_back:'%s'}" % (
self.id, self.uid, self.apply_time, self.status, self.check_time, 
self.checker, self.realname, self.id_no, self.id_pic_front, self.id_pic_back)

    __repr__ = __str__


